/*!
 * \file entity_impl.cpp
 */

#include "common.hpp"

/******************************************************************************************/
/*!
 * \brief Checks to see whether the bounding radii of the two specified entities overlap;
 * returns true if they do, or false otherwise.
 *
 * \note Will call each entity's on_hit() function if it's determined that they do overlap.
 */
bool ENTITY::check_collision(ENTITY &a, ENTITY &b)
{
    float distance;
    float sum_radii;

    distance    = hypotf(b.x - a.x, b.y - a.y);
    sum_radii   = a.radius + b.radius;

    // are they touching?
    if (sum_radii <= distance)
    {
        // yes.
        a.on_hit(b);
        b.on_hit(a);
        return true;
    }

    // no.
    return false;
}
